<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
		
		
		<script src="jquery-3.6.0.min.js" type="text/javascript"></script>
		<script>
			$(function(){
				$.ajax({
					type: "get",
					url: "http://localhost:9999",
					data: {
						   "name" : "kuangshenshuo",
						   "age":  12,
						   "sex": "男"
					},
					dataType: "text",
					success: function(data) {
						var obj=JSON.parse(data);//字符串转化为json对象
						var  str="";
						for(var i=0;i<obj.length;i++){
							str=str+"<tr  align='center'>";
							str=str+"<td><a href='http://localhost:8080/user/info?id="+obj[i].id+"'>"+obj[i].id+"</a></td>";
							str=str+"<td>"+obj[i].name+"</td>";
							str=str+"<td>"+obj[i].age+"</td>";
							str=str+"<td>"+obj[i].sex+"</td>";
							str=str+"<td><input  type='button'  onclick='fun1("+obj[i].id+")'  value='删除'/></td>";
							str=str+"<td><a href='http://localhost:8080/user/update?id="+obj[i].id+"'>修改</a></td>";
							str+=" </tr>";
						}
						$("#form1").append(str);
						
					},
					error:function(data){
						alert("错误1");
					}
					
				})
				
			})
			
			
			//删除用户的信息
			function  fun1(id){
			 $.ajax({
					type: "get",
					url: "http://localhost:8080/user/delete",
					data: {"id":id},
					dataType: "text",
					success: function(data) {
						var obj=JSON.parse(data);//字符串转化为json对象
						var  str="";
						for(var i=0;i<obj.length;i++){
							str=str+"<tr  align='center'>";
							str=str+"<td><a href='http://localhost:8080/user/info?id="+obj[i].id+"'>"+obj[i].id+"</a></td>";
							str=str+"<td>"+obj[i].name+"</td>";
							str=str+"<td>"+obj[i].age+"</td>";
							str=str+"<td>"+obj[i].sex+"</td>";
							str=str+"<td><input  type='button'  onclick='fun1("+obj[i].id+")'  value='删除'/></td>";
							str=str+"<td><a href='http://localhost:8080/user/update?id="+obj[i].id+"'>修改</a></td>";
							str+=" </tr>";
						}
						
						
						var  head="<tr><th colspan='6'><h1>表格数据</h1></th></tr><tr  align='center'>";
					         head=head+"<td>ID编号</td><td>名称</td><td>年龄</td><td>性别</td></tr>";
						$("#form1").html(head+str);
						
					},
					error:function(data){
						alert("错误2");
					}
					
				})
			}
			
			
		</script>
	</head>
	<body>
	</body>
</html>
